home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / gnugo1_1.lha / gnugo / findopen.c < prev    next >
C/C++ Source or Header  |  1989-03-07  |  3KB  |  117 lines

  1. /*
  2.                 GNU GO - the game of Go (Wei-Chi)
  3.                 Version 1.1   last revised 3-1-89
  4.            Copyright (C) Free Software Foundation, Inc.
  5.                       written by Man L. Li
  6.                       modified by Wayne Iba
  7.                     documented by Bob Webber
  8. */
  9. /*
  10. This program is free software; you can redistribute it and/or modify
  11. it under the terms of the GNU General Public License as published by
  12. the Free Software Foundation - version 1.
  13.  
  14. This program is distributed in the hope that it will be useful,
  15. but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17. GNU General Public License in file COPYING for more details.
  18.  
  19. You should have received a copy of the GNU General Public License
  20. along with this program; if not, write to the Free Software
  21. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  22.  
  23. Please report any bug/fix, modification, suggestion to
  24.  
  25. mail address:   Man L. Li
  26.                 Dept. of Computer Science
  27.                 University of Houston
  28.                 4800 Calhoun Road
  29.                 Houston, TX 77004
  30.  
  31. e-mail address: manli@cs.uh.edu         (Internet)
  32.                 coscgbn@uhvax1.bitnet   (BITNET)
  33.                 70070,404               (CompuServe)
  34. */
  35.  
  36. #include <stdio.h>
  37.  
  38. #define EMPTY 0
  39.  
  40. extern unsigned char p[19][19], ma[19][19];
  41. extern int mik, mjk;  /* piece captured */
  42.  
  43. findopen(m, n, i, j, color, minlib, ct)
  44. /* find all open spaces i, j from m, n */
  45. int m, n, i[], j[], color, minlib, *ct;
  46. {
  47. /* mark this one */
  48.  ma[m][n] = 1;
  49.  
  50. /* check North neighbor */
  51.  if (m != 0)
  52.    {
  53.     if ((p[m - 1][n] == EMPTY) && (((m - 1) != mik) || (n != mjk)))
  54.       {
  55.        i[*ct] = m - 1;
  56.        j[*ct] = n;
  57.        ++*ct;
  58.        if (*ct == minlib) return 1;
  59.      }
  60.     else
  61.       if ((p[m - 1][n] == color) && !ma[m - 1][n])
  62.      if (findopen(m - 1, n, i, j, color, minlib, ct) && (*ct == minlib))
  63.         return 1;
  64.   }
  65.  
  66. /* check South neighbor */
  67.  if (m != 18)
  68.    {
  69.     if ((p[m + 1][n] == EMPTY) && (((m + 1) != mik) || (n != mjk)))
  70.       {
  71.        i[*ct] = m + 1;
  72.        j[*ct] = n;
  73.        ++*ct;
  74.        if (*ct == minlib) return 1;
  75.      }
  76.     else
  77.       if ((p[m + 1][n] == color) && !ma[m + 1][n])
  78.      if (findopen(m + 1, n, i, j, color, minlib, ct) && (*ct == minlib))
  79.         return 1;
  80.   }
  81.  
  82. /* check West neighbor */
  83.  if (n != 0)
  84.    {
  85.     if ((p[m][n - 1] == EMPTY) && ((m != mik) || ((n - 1) != mjk)))
  86.       {
  87.        i[*ct] = m;
  88.        j[*ct] = n - 1;
  89.        ++*ct;
  90.        if (*ct == minlib) return 1;
  91.      }
  92.     else
  93.       if ((p[m][n - 1] == color) && !ma[m][n - 1])
  94.      if (findopen(m, n - 1, i, j, color, minlib, ct) && (*ct == minlib))
  95.         return 1;
  96.   }
  97.  
  98. /* check East neighbor */
  99.  if (n != 18)
  100.    {
  101.     if ((p[m][n + 1] == EMPTY) && ((m != mik) || ((n + 1) != mjk)))
  102.       {
  103.        i[*ct] = m;
  104.        j[*ct] = n + 1;
  105.        ++*ct;
  106.        if (*ct == minlib) return 1;
  107.      }
  108.     else
  109.       if ((p[m][n + 1] == color) && !ma[m][n + 1])
  110.      if (findopen(m, n + 1, i, j, color, minlib, ct) && (*ct == minlib))
  111.         return 1;
  112.   }
  113.  
  114. /* fail to find open space */
  115.  return 0;
  116. }  /* end findopen */
  117.